package com.lee9213.conference.track.management.handler;

import com.lee9213.conference.track.management.constant.Constant;
import com.lee9213.conference.track.management.entity.SessionEntity;
import com.lee9213.conference.track.management.entity.TalkEntity;
import com.lee9213.conference.track.management.entity.TrackEntity;

import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @author lee9213@163.com
 * @version 1.0
 * @date 2018-07-11 23:23
 */
public class NetworkingFilter implements Filter {
    @Override
    public void build(List<TalkEntity> allTalkEntities, TrackEntity trackEntity, FilterChain filterChain) {
        String startTime = trackEntity.getLastTime();
        LocalTime localTime = LocalTime.parse(startTime);
        if (localTime.isBefore(LocalTime.parse(Constant.NETWORKING_MIN_START_TIME))) {
            localTime = LocalTime.parse(Constant.NETWORKING_MAX_START_TIME);
        }
        SessionEntity networking = new SessionEntity(startTime);
        List<TalkEntity> networkingTalkEntities = new ArrayList<>();
        networkingTalkEntities.add(new TalkEntity(Constant.NETWORKING_TALK_TITLE, localTime.toString()));
        networking.setTalkEntity(networkingTalkEntities);
        trackEntity.addSessionEntity(networking);
        filterChain.doFilter(allTalkEntities, trackEntity);
    }
}
